package m202401.d04;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/4 09:17
 */
//452. 用最少数量的箭引爆气球
public class Q452 {

    public static void main(String[] args) {
        System.out.println(new Q452().findMinArrowShots(new int[][]{
                {3, 9}, {7, 12}, {3, 8}, {6, 8}, {9, 10}, {2, 9}, {0, 9}, {3, 9}, {0, 6}, {2, 8}
        }));
    }

    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, Comparator.comparingInt(x -> x[0]));
        int res = 0;
        int max = points[0][1];
        for (int i = 1; i < points.length; i++) {
            int[] current = points[i];
            if (current[0] > max) {
                res++;
                max = current[1];
                continue;
            }
            max = Math.min(max, current[1]);
        }
        res++;
        return res;
    }
}
